<template>
	<view>
		<view class="contentCla">
			<view class="titleCla">
				{{name.titleName}}
			</view>
			<view class="textCla">
				{{name.Content}}
			</view>
			<view class="boxCla">
				<view class="qiyedizhiCla">
					企业地址
				</view>
				<view class="AddCla">
					<radio-group class="uni-list" @change="groupChange">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item,index) in qiyedizhiList"
							:key="index">
							<view class="itemCla">
								<radio :value="item.Address" :checked="index===current1"></radio>
								<view class="itemtextCla">
									<view class="itemPaddCla">
										{{item.NameAddress}}
									</view>
									<view :class="item.NameAddress?'itemAddCla':'itemPaddCla'">
										<text>{{item.Address}}</text>
									</view>
								</view>

							</view>
						</label>
					</radio-group>
				</view>
				<view class="qiyedizhiCla">
					其他地址
				</view>
				<view class="tianjiaCla" @click="addClick(name)">
					添加
				</view>
				<view class="AddCla">
					<radio-group class="uni-list" @change="radioChange">
						<label class="uni-list-cell uni-list-cell-pd" v-for="(item,index) in addList" :key="index">
							<view class="itemCla">
								<radio :value="item.Address" :checked="index===current"></radio>
								<view class="itemtextCla">
									<view class="itemPaddCla">
										<text v-if="item.ShortAddress">{{item.ShortAddress}}</text>
									</view>
									<view :class="item.ShortAddress?'itemAddCla':'itemPaddCla'">
										<text>{{item.Address}}</text>
									</view>
								</view>
								<view class="iconCla" @click="deleteClick(item)">
									<u-icon name="close-circle-fill" color="#999999" size="19"></u-icon>
								</view>
							</view>
						</label>
					</radio-group>
				</view>
			</view>
		</view>
		<u-modal :show="show" :content='content' :showCancelButton="true" @confirm="confirmClick"
			@cancel="cancelClick"></u-modal>
	</view>
</template>

<script>
	import {
		data
	} from '../../../uni_modules/uview-ui/libs/mixin/mixin';
	export default {
		data() {
			return {
				qiyedizhiList: [],
				addList: [],
				addlist1: [],
				PageIndex: 1,
				PageSize: 10,
				show: false,
				content: '确定删除该地址么？',
				groupzhuangtai: false,
				current: null,
				current1:null,
				obj:{},
				id:'',
			}
		},
		props: {
			name: {
				type: Object
			},
			nameShow: {
				type: Boolean,
				default: false
			}
		},
		watch:{
			nameShow(newVal){
				if(newVal){
					this.$emit('toguanjianciData',this.obj)
				}
			}
		},
		created() {
			this.getJobAddress();
			this.addAddress();
		},
		methods: {
			groupChange(n) {
				this.current = null
				for (let i = 0; i < this.qiyedizhiList.length; i++) {
					if (this.qiyedizhiList[i].Address == n.detail.value) {
						this.current1 = i;
						this.obj = this.qiyedizhiList[i]
						break;
					}
				}
			},
			radioChange(n) {
				this.current1 = null
				for (let i = 0; i < this.addList.length; i++) {
					if (this.addList[i].Address == n.detail.value) {
						this.current = i;
						this.obj = this.addList[i]
						break;
					}
				}
			},
			// 获取企业地址
			getJobAddress() {
				// let CorpId = uni.getStorageSync("dianjiqiye").Id;
				let obj = {
					Type: 0, //0企业地址 1其它地址
					PageIndex: this.PageIndex,
					PageSize: this.PageSize
				}
				this.$http.core.tenantAddress(obj).then((res) => {
					if (res.Success) {
						this.qiyedizhiList = this.qiyedizhiList.concat(res.Result.Items);
					}
				});
			},
			addClick(name) {
				name.Address = '';
				name.AreaCode = '';
				name.CityCode = '';
				name.ProvinceCode = '';
				name.PcaAddress = '';
				name.NameAddress = ''; //详细地址上边的地址
				name.value = '';
				uni.redirectTo({
					url: '/pages/views/packageC/type-recruit/zhiwei/addAddress?data=' + JSON.stringify(name)
				})
			},
			addAddress() {
				// let CorpId = uni.getStorageSync("dianjiqiye").Id;
				let obj = {
					Type: 1, //0企业地址 1其它地址
					PageIndex: this.PageIndex,
					PageSize: this.PageSize
				}
				this.$http.core.tenantAddress(obj).then((res) => {
					if (res.Success) {
						console.log(res, '获取企业其他地址---------')
						this.addList = this.addList.concat(res.Result.Items);
					}
				})
			},
			//删除其他企业地址
			deleteClick(item) {
				this.show = true;
				this.id = item.Id;
			},
			// 取消按钮的点击事件
			cancelClick() {
				this.show = false;
			},
			// 确定删除点击事件
			confirmClick() {
				console.log(this.id)
				this.$http.core.tenantDel_address(this.id).then((res) => {
					if(res.Success){
						this.$util.toast('删除成功')
						this.show = false;
						this.addAddress()
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.contentCla {
		background-color: #fff;
		width: 100%;
		min-height: 100vh;

		.titleCla {
			padding: 60rpx 40rpx 10rpx 40rpx;
			font-size: 48rpx;
			font-weight: bold;
			color: #000000;
		}

		.textCla {
			padding: 0 40rpx 10rpx 40rpx;
			font-weight: 500;
			color: #666666;
			font-size: 28rpx;
		}

		.boxCla {
			padding: 20rpx 40rpx 0 40rpx;

			.qiyedizhiCla {
				font-size: 34rpx;
				font-weight: bold;
				color: #000000;
				margin: 63rpx 0 20rpx;
			}

			.AddCla {
				.itemCla {
					display: flex;
					align-items: center;
					margin-top: 20rpx;

					.itemtextCla {
						width: 90%;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;

						.itemPaddCla {
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-size: 30rpx;
							font-family: PingFang SC-Bold, PingFang SC;
							font-weight: bold;
							color: #000000;
						}

						.itemAddCla {
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							color: #949494;
						}
					}
				}

			}

			.tianjiaCla {
				width: 211rpx;
				height: 76rpx;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				opacity: 1;
				border: 1rpx solid #3476FE;
				font-size: 26rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #3476FE;
				display: flex;
				justify-content: center;
				align-items: center;
			}

		}

	}
</style>